package com.inplaceedit.client.activity.menu;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.inject.Inject;
import com.core.gwt.ui.client.HyperString;
import com.inplaceedit.client.support.ApplicationPlace;

public class MenuActivityImpl extends AbstractActivity implements MenuActivity {
	public static interface View extends IsWidget {
		void setItems(List<HyperString> items);
	}

	@Inject
	private View view;
	@Inject
	private PlaceHistoryMapper placeMapper;

	@Override
	public void setPlace(final ApplicationPlace place) {
	}

	@Override
	public void start(final AcceptsOneWidget panel, final EventBus eventBus) {
		view.setItems(getMenuItems());
		panel.setWidget(view);
	}

	private List<HyperString> getMenuItems() {
		final List<HyperString> items = new ArrayList<HyperString>();
		for (final ApplicationPlace place : MenuPlaceList.get()) {
			items.add(new HyperString(PlaceTypeRenderer.get().render(
					place.getType()), placeMapper.getToken(place)));
		}
		return items;
	}
}
